package com.itheima.web;

import com.itheima.entity.Brand;
import com.itheima.service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    private BrandService brandService=new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      request.setCharacterEncoding("utf-8");
      String brandId = request.getParameter("id");
        String brandName = request.getParameter("brandName");
        //解决乱码问题
        String companyName = request.getParameter("companyName");
        String orderedParam = request.getParameter("ordered");

        String description = request.getParameter("description");
        // 状态：0：禁用  1：启用
        String statusParam = request.getParameter("status");
        Brand newbrand=new Brand();
        newbrand.setId(Integer.parseInt(brandId));
        newbrand.setBrandName(brandName);
        newbrand.setCompanyName(companyName);
        newbrand.setOrdered(Integer.parseInt(orderedParam));
        newbrand.setDescription(description);
        newbrand.setStatus(Integer.parseInt(statusParam));
        brandService.update(newbrand);
        request.getRequestDispatcher("/SelectAllServlet").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
